home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-06 | 4.2 KB | 201 lines | [TEXT/MSET] |
- \ 28Oct94 dbh updated to 2.5 syntax
- \ note, need to respond to deactivate:/activate:
-
- (*
-
- Class popup allows us to easily have popup menus in a selwindow by following
- our standard selection protocol. Popups are subclassed from the standard Mops
- menu class so storing xts for the popup to execute is just like for standard
- menus. One unique feature of the popup class is we need not specify a menu
- ID because the new: method will simply choose a unique ID for us, we don't
- care which.
-
- These popups are not resource-based.
-
- Also, in keeping with our philosophy that a minimum, preferably no, setup
- should be required to use our objects, class popup will function quite
- nicely simply by instantiating and adding to our selwindow.
-
- *)
-
-
- :class popup super{ menu nullselect }
- bool alive
- rect+ popupbox
- text16 title \ font will be contained in the title
- rect+ titlebox
- int currentitem#
- 32 $x itemList$ \ we limit the initial string sizes to a total of 32
- \ but we can add all we want after new: of course
-
- :m init: ( ... xts ... n -- )
- put: super ;m
-
- :m get: ( -- n) \ will return the 0-based index of the currently
- \ selected menu item
- get: currentitem# ;m
-
- :m settitle: ( addr len -- )
- put: title ;m
-
- :m setItemList: ( addr len -- )
- put: itemList$ ;m
-
- :m classinit:
- clear: alive
- " Chicago" fontname: title
- 12 fontsize: title
- " popup" settitle: self
- 0 put: currentitem#
- " item0" setItemList: self
- limit 0 DO
- ['] null LOOP limit
- init: self
- ;m
-
- :m hit?: \ ( -- b )
- where: theMouse
- popupbox PtinRect ;m
-
- :m del:
- \ draw the del
- getx2: popupbox 14 - ( x)
- gety2: popupbox 9 - ( y) MoveTo
- del ;m
-
-
- :m drawMenuItem:
- set: title \ sets our font
- Call PenNormal \ just in case!
- 1 1 inset: popupbox
- clear: popupbox
- -1 -1 inset: popupbox
- \ now draw the text in the box, it will be the current item text
- getx1: popupbox 4 + ( x)
- gety1: popupbox 13 + ( y) MoveTo
- get: currentitem# getitem: super mDrawString
- del: self
- ;m
-
- :m draw:
- call PenNormal
- dropshadow: popupbox
- drawMenuItem: self
-
- \ and finally, the title
- getx1: titlebox ( x)
- gety1: titlebox 12 + ( y) MoveTo
- draw: title
- ;m
-
- :m click: { \ olditem newitem -- }
- invert: titlebox
- get: currentitem# -> olditem
- 0 \ room for result
- get: mhndl
- topint: popupbox \ a packed point
- l->g unpack swap pack \ top, left
- get: currentitem# 1 + makeint \ PopUpItem
- call PopUpMenuSelect
- unpack drop 1 - -> newitem \ our item#, 1 less than toolbox's
-
- newitem 0>=
- IF
- olditem uncheck: super
- newitem check: super
- newitem put: currentitem#
- newitem exec: [self] \ 03Sep94 dbh late bind so subclasses can be different
- normal: super
- drawMenuItem: self
- THEN
- invert: titlebox
- ;m
-
- :m titlewidth: ( -- w)
- word0 get$: title call StringWidth i->l ;m
-
- private
- :m resize: { \ wid -- }
- get: alive not IF exit THEN
- get: mhndl call CalcMenuSize \ this will set the tbox record sizes
- get: mhndl @ 2 + w@ ( width ) 18 ( height) \ get the tbox record size
- setsize: popupbox \ and set our rect size to match
-
- \ finally, set up our title box to the correct position and size
- get: popupbox put: titlebox
- titlewidth: self -> wid
- wid setwidth: titlebox
- wid 1 + negate 0 move: titlebox
- 0 -3 stretch: titlebox
- ;m
- public
-
- :m new: { wptr -- }
- \ don't need wptr, but must follow select protocol
-
- id: menuList put: resid \ automatically assign an ID, we don't care which
-
- getnew: title
-
- get: title new: super \ now it's a toolbox menu
- set: alive \ mark as alive so resize: will function
-
- get: itemList$ add: super \ append our item(s)
-
- resize: self
-
- get: mhndl -1 makeint call InsertMenu \ -1 indicates a popup
-
- get: currentitem# check: super
-
- ;m
-
- :m add: ( addr len -- )
- add: super
- resize: self ;m
-
- :m release:
- release: super
- clear: alive ;m
-
- :m move: { dx dy -- }
- dx dy move: titleBox
- dx dy move: popupbox
- resize: self
- ;m
-
- :m moveto: { x y -- }
- x y moveto: titleBox
- x y moveto: popupbox
- resize: self
- ;m
-
- ;class
-
- endload
-
- *** EXAMPLE USE
-
- selwindow ww
- test: ww
-
- 4 popup pp
- " item0;item1;item2;item3" setItemList: pp
- 100 100 moveto: pp
- pp add: ww
-
- : noise 1 beep ;
-
- xts{ noise null noise null } init: pp
-
- 3 popup pp2
- 75 50 moveto: pp2
- " Transp:" settitle: pp2
- " Trains;Boats;Planes" setItemList: pp2
- pp2 add: ww
-
-
- pushButton bb
- 100 75 moveto: bb
- bb add: ww
-